﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Common
{
    [Serializable]
    public class User
    {
        public long Id;
        public string UserName;
        public string Email;
        public string FirstName;
        public string LastName;
        public List<string> UserQueries = new List<string>();
        public List<Category> Categories;

        public User(long id, string userName, string email, string firstName, string lastName, List<Category> categories)
        {
            Id = id;
            UserName = userName;
            Email = email;
            FirstName = firstName;
            LastName = lastName;
            Categories = categories;
        }


        public List<DomainPriority> GetDomainPrioritiesByCategory(string Name)
        {
            foreach (Category cat in Categories)
            {
                if (cat.Name == Name)
                    return cat.DomainPriorities;

            }
            //return null;
			return new List<DomainPriority>();
        }

        public override string ToString()
        {
            return Id + " " + UserName;
        }

        public Category GetCategoryByName(string categoryName)
        {
            foreach (Category cat in Categories)
            {
                if (cat.Name.Equals(categoryName))
                    return cat;
            }
            return null;
        }

        public Category this[string categoryName]
        {
            get
            {
                foreach (Category cat in Categories)
                { if (cat.Name == categoryName) return cat; }
                return null;
            }
            set
            {
                foreach (Category cat in Categories)
                { if (cat.Name == categoryName) { Categories.Remove(cat); break; } }
                value.Name = categoryName;
                Categories.Add(value);
            }
        }

    }
}
